$(function(){
    // 新增信息
   /* $('.info_toggle_btn').on('click', function(){
        var that = $(this);
        var oLi = that.parent('li');
        if(that.html() == "新增信息"){
            that.html("选择已有信息");
            oLi.find('[type="hidden"]').val("new");
            oLi.find('select').hide();
            oLi.find('[type="text"]').show();
        } else {
            that.html("新增信息");
            oLi.find('[type="hidden"]').val(" ");
            oLi.find('select').show();
            oLi.find('[type="text"]').hide();
        }
    });
*/
    // 模板类型切换
    $('#type-toggle input').on('change', function(){
        var personItem = $(this).closest('ul').find('.person_item');
        var companyItem = $(this).closest('ul').find('.company_item');
        // var personItem1 = $(this).closest('ul').find('.person_item1');
        if($(this).data('type') == "person"){
            personItem.show();
            companyItem.hide();
            /*personItem1.hide();*/
        } else {
            personItem.hide();
            companyItem.show();
           /* personItem1.show();*/
        }
    });

    $('#add_form').ajaxForm({
        dataType: "json",
        beforeSubmit: function(formData, jqForm, options) {
            layer.load(2);
        },
        success: function(data) {
            if(data.code == "1") {
                window.location.href = data.url;
            } else {
                layer.msg(data.msg);
            }
        },
        //ret.status != 200 时回调
        error: function(ret) { },
        //无论是 success 还是 error，最终都会被回调
        complete: function(ret) { layer.closeAll('loading'); }
    });

    // 企业名称
    toPinYin("select[name='authCompanyId']", "input[name='company_name_en']");
    toPinYin("input[name='company_name']", "input[name='company_name_en']");
    // 省份
    toPinYin("#s_province", "input[name='province_en']");
    // 城市
    toPinYin("#s_city", "input[name='city_en']");
    // 地址
    toPinYin("input[name='address']", "input[name='address_en']");
    // 域名所有者姓名
    toPinYin("select[name='authIdCardId']", "input[name='person_name_en']");
    toPinYin("input[name='person_name']", "input[name='person_name_en']");
});

